import sys
import vlc
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget, QFileDialog
from PyQt5.QtCore import Qt

class VideoPlayer(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("Video Player")
        self.setGeometry(100, 100, 800, 600)

        self.instance = vlc.Instance()
        self.media_player = self.instance.media_player_new()

        self.init_ui()

    def init_ui(self):
        self.widget = QWidget(self)
        self.setCentralWidget(self.widget)

        layout = QVBoxLayout()
        self.widget.setLayout(layout)

        # Create a button to open a file dialog and select a video file.
        self.open_button = QPushButton('Open Video', self)
        self.open_button.clicked.connect(self.open_file)
        layout.addWidget(self.open_button)

        # Create a frame for the video output.
        self.video_frame = QWidget(self)
        palette = self.video_frame.palette()
        palette.setColor (self.video_frame.backgroundRole(), Qt.black)
        self.video_frame.setPalette(palette)
        self.video_frame.setAutoFillBackground(True)
        layout.addWidget(self.video_frame)

    def open_file(self):
        filename, _ = QFileDialog.getOpenFileName(self, "Open Video", "", "Video Files (*.mp4 *.flv *.ts *.mts *.avi *.mkv)")
        if filename != '':
            self.media = self.instance.media_new(filename)
            self.media_player.set_media(self.media)

            if sys.platform == "darwin":  # MacOS
                self.media_player.set_nsobject(int(self.video_frame.winId()))
            elif sys.platform == "win32":  # Windows
                self.media_player.set_hwnd(int(self.video_frame.winId()))
            else:  # Linux
                self.media_player.set_xwindow(int(self.video_frame.winId()))

            self.media_player.play()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    player = VideoPlayer()
    player.show()
    sys.exit(app.exec_())